<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        function throwIfMissing() {
        //   主动抛出一个异常
            throw new Error("不能省略参数");
        }
        // throwIfMissing();

        function foo(mustBeProvided = throwIfMissing()){
            return mustBeProvided;
        }
       
        foo();


        // es5,如果param过多，就要写很多分支
        function foo1(param,param1){
            if(param === undefined){
                throwIfMissing();
            }
        }

        // es6
        function foo2(param1 = throwIfMissing(),param2 = throwIfMissing()){
            console.log(param1,param2);
        }
    </script>
</body>
</html>